﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Requests.RequestBases.Common;
using Core.GenericDefinitions.BaseClasses;
using Core.DataBaseAccess;
using Core.GenericDefinitions;
using System.Collections.ObjectModel;
using System.Data.Linq;

namespace Core.Requests.SRVUICommonRequests
{
    public class HelloRequest : HelloRequestBase
    {
        public override ResponseBase Process()
        {
            ResponseBase rb = new ResponseBase { ReturnValue = Name + " Tamamdır" };
            return rb;
        }
    }


    /// <summary>
    /// Requests.ServiceRequests
    /// Kullanıcıları listeleyen request
    /// </summary>
    public class ListUserRequest : ListUserRequestBase
    {
        public override ResponseBase Process()
        {
            ResponseBase rb = new ResponseBase();
            return rb;
        }
    }

    /// <summary>
    /// Requests.ServiceRequests
    /// Kullanıcı adı ve şifresini göndererek loginRequest yapar
    /// </summary>
    public class LoginRequest : LoginRequestBase
    {
        public override ResponseBase Process()
        {
            ResponseBase rb = new ResponseBase();
            EOrgDataClassesDataContext dc = new EOrgDataClassesDataContext();
            ISingleResult<sel_UserInfoResult> result = dc.sel_UserInfo(LoginInfo.UserName, LoginInfo.Password);

            //Login Failed
            if (result.Count() != 1)
            {
                rb.Message = "Kullanıcı Bulunamadı";
                return rb;
            }

            sel_UserInfoResult r = result.ElementAt<sel_UserInfoResult>(0);
            User usr = new User
            {
                Name = r.Name,
                Surname = r.Surname,
                EMail = r.Email,
                UserName = this.LoginInfo.UserName,
                IsLoggedIn = true
            };


            rb.ReturnValue = usr;

            return rb;
        }
    }

    /// <summary>
    /// Requests.ServiceRequests
    /// Logout yapan request.
    /// </summary>
    public class LogoutRequest : LogoutRequestBase
    {
        public override ResponseBase Process()
        {
            ResponseBase rb = new ResponseBase();
            rb.ReturnValue = null;
            return rb;
        }
    }
}
